package com.yvon.maple.service.msg.core.handler.handler;

import com.yvon.maple.service.msg.core.common.domain.TaskInfo;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;

/**
 * 发送各个渠道的handler
 *
 * @author : Yvon
 * @since : 2021-12-23
 */
public abstract class Handler {

    /**
     * 渠道标识
     * 子类初始化的时候指定
     */
    protected Integer channelCode;


    @Autowired
    private HandlerHolder handlerHolder;

    @PostConstruct
    private void init() {
        handlerHolder.putHandler(channelCode, this);
    }

    public void doHandler(TaskInfo taskInfo) {
        handler(taskInfo);
    }

    /**
     * 处理程序
     *
     * @param taskInfo 任务信息
     * @return void
     * @author : Yvon / 2021-12-23
     */
    public abstract void handler(TaskInfo taskInfo);

}
